package com.hookgetaway

import android.app.AlarmManager
import android.content.Context
import android.os.Build
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.TextView
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import com.hookgetaway.utils.SystemSettingGuideHelper
import java.lang.Boolean


class MainActivity : AppCompatActivity() {
    @RequiresApi(Build.VERSION_CODES.S)
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
//        SystemSettingGuideHelper.handleAutoStartSettings()
//        SystemSettingGuideHelper.openPowerSaveSettings(this)
        var tv = findViewById<TextView>(R.id.tv_alarm)
        // 实例化AlarmManager
        val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager

        tv.setOnClickListener {
            // 调用O1方法
            O1(alarmManager, this, tv)
        }
    }


    @RequiresApi(Build.VERSION_CODES.S)
    fun O1(
        alarmManager: AlarmManager,
        checkPermissionActivity: MainActivity,
        view: View?
    ) {
        if (!alarmManager.canScheduleExactAlarms()) {
            if (!SystemSettingGuideHelper.t(view, SystemSettingGuideHelper.createExactAlarmSettingsGuide())) {
                Log.d("MainActivity",getString(R.string.open_setting_failed_diy))

            }
            return
        }
        Log.e("MainActivity","已获得权限，无需再设置")
    }

}